package cn.dqy.gotanserver.support;

import cn.dqy.gotanserver.code.CodeUtils;
import cn.dqy.gotanserver.dto.ChannelInfo;
import cn.dqy.gotanserver.config.ConfigClass;
import cn.dqy.gotanserver.dto.GoTanInet;
import cn.dqy.gotanserver.dto.GoTanObject;
import cn.dqy.gotanserver.service.CoreServer;
import cn.dqy.gotanserver.support.msghandle.MsgProcessHanldeRegistrar;
import cn.dqy.gotanserver.support.msghandle.MsgProcessInterface;
import com.google.gson.Gson;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Queue;

@Component
public class SupportHelper {
    static Logger logger = LoggerFactory.getLogger(SupportHelper.class);

    @Autowired
    ConfigClass configClass;

    @Autowired
    ClientRespondRecordUtils clientRespondRecordUtils;

    @Autowired
    CoreServer coreServer;

    @Autowired
    MsgProcessHanldeRegistrar msgProcessHanldeRegistrar;

    public void save(GoTanInet goTanInet,String ipAndPoet){
        String val = new String(goTanInet.getVal_data(), CodeUtils.globalCharSet); //包的JSON描述信息

        Gson gson = new Gson();
        GoTanObject goTanObject = gson.fromJson(val, GoTanObject.class);
        String remark = goTanObject.getRemark();

        MsgProcessInterface process = msgProcessHanldeRegistrar.getProcess(remark);
        if(process==null){
            logger.error("取得消息处理器失败...请检查条件");
            clientRespondRecordUtils.wInfo("严重错误，取得消息处理器失败",true,false);
            return;
        }
        process.process(goTanInet,goTanObject,ipAndPoet);

    }
}
